package com.igeek.collateral.controller;

import com.igeek.collateral.constant.MessageConstant;
import com.igeek.collateral.entity.Menu;
import com.igeek.collateral.entity.Role;
import com.igeek.collateral.entity.User;
import com.igeek.collateral.result.Result;
import com.igeek.collateral.service.IMenuService;
import com.igeek.collateral.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/menuRole")
@Api(tags = "菜单添加角色接口")
@Slf4j
public class MenuRoleController {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IRoleService roleService;

//    @PostMapping("add")
//    @ApiOperation("添加角色信息")
//    public Result add(@RequestBody Menu menu, @RequestParam("roleIds") Integer[] roleIds){
//        boolean flag = menuService.add(menu,roleIds);
//        if(flag){
//            return new Result(true , "添加角色信息成功");
//        }
//        return new Result(false , "添加角色信息失败");
//    }
//    @GetMapping("findRoleByMenuId/{id}")
//    @ApiOperation("根据菜单编号查询所有角色信息")
//    public Result findRoleByMenuId(@PathVariable("id") Integer menuId){
//        List<Integer> roleIds = menuService.findRoleMenuId(menuId);
//        if(!CollectionUtils.isEmpty(roleIds)){
//            return new Result(true , "通过菜单编号查询角色信息成功" , roleIds);
//        }
//        return new Result(true , "通过菜单编号查询角色信息失败");
//
//    }

    @GetMapping("findR")
    @ApiOperation("查询所有角色信息")
    public Result findAll() {
        List<Role> roles = roleService.list();
        if(!CollectionUtils.isEmpty(roles)){
            return new Result(true , "通过菜单编号查询角色信息成功" ,roles);
        }
        return new Result(true , "通过菜单编号查询角色信息失败");
    }


//    @PutMapping("update")
//    @ApiOperation("更新菜单信息信息")
//    public Result update(@RequestBody Menu menu , @RequestParam("roleIds") Integer[] roleIds){
//        boolean flag = menuService.updateMenu(menu,roleIds);
//        if(flag){
//            return new Result(true , "更新菜单信息成功");
//        }
//        return new Result(false , "更新菜单信息失败");
//    }

//    @DeleteMapping("{id}")
//    @ApiOperation("根据id删除菜单信息")
//    public Result delete(@PathVariable("id") Integer menuId) {
//        boolean flag = menuService.del(menuId);
//        if(flag){
//            return new Result(true , "删除菜单信息成功");
//        }
//        return new Result(false , "删除菜单信息失败");
//    }
}
